var api = require('../../util/api.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isEdit: true
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var _this = this;
    if (api.isBlank(options.id)) {
      _this.setData({
        isEdit: false,
        item: {},
        imgList: []
      });
    } else {
      api.get(`${api.url.wtmxb}/${options.id}`).then(res => {
        _this.setData({
          item: res.data
        });
      })
    }
  },
  formSubmit(e) {
    var _this = this;
    var params = e.detail.value;
    if (_this.data.isEdit) {
      api.put(api.url.wtmxb, params).then(res => {
        api.back("修改成功", "success");
      })
    } else {
      params.examineId = _this.options.examineId;
      params.userId = _this.options.userId;
      params.userName = _this.options.userName;
      params.checker =  _this.options.userName;
      api.post(api.url.wtmxb, params).then(res => {
        api.back("新增成功", "success");
      })
    }
  }
})